<template>
	<layout :loading="loading" curPage="company" :title="data.id ? '修改企业':'新增企业'">
	
		<form class="layui-form" @submit="submit" data-action="/admin/company/save" data-rediret="/pages/company/companyList">
			
			<inputGroup type="text" title="企业名称" name="x.name|企业名称|0~100" :value="data.name"  placeholder="请输入企业名称"></inputGroup>
			<inputGroup type="text" title="通用名称" name="x.simpleName|通用名称|0~100|empty" :value="data.name"  placeholder="请输入通用名称"></inputGroup>
			<inputGroup type="text" title="曾用名" name="x.nameUsedBefore|曾用名|0~100|empty" :value="data.name"  placeholder="请输入曾用名"></inputGroup>
			
			<view @tap="chooseLocation" >
				<inputGroup type="text" title="经纬度" name="x.latitude|经纬度|0~500" :disabled="true" :value="`${data.latitude},${data.longitude}`" :hiddenValue="data.latitude" addOn="去选择经纬度"></inputGroup>
				<inputGroup type="hidden" title="经纬度" name="x.longitude|纬度|0~500" :disabled="true" v-model="data.longitude" ></inputGroup>
			</view>
			
			<inputGroup type="text" title="企业地址" name="x.address|企业地址|0~500" :value="data.address" placeholder="请输入企业地址"></inputGroup>
			
			<inputGroup type="text" title="行业" name="x.industry|行业|0~100" :value="data.industry"  placeholder="请输入行业"></inputGroup>
			
			<inputGroup type="text" title="联系人" name="x.contacts|联系人|0~50" :value="data.contacts"  placeholder="请输入联系人"></inputGroup>
			
			<inputGroup type="number" title="手机号码" name="x.mobile|手机号码|mobile" :value="data.mobile"  placeholder="请输入手机号码"></inputGroup>
			
			
			<div class="layui-form-item">
				<div class="layui-input-block" style="margin-left: 140px;">
					<input type="hidden" name="x.id" :value="data.id" style="display: none;">
					<button class="layui-btn" form-type="submit">{{ !data.id ? '保存' : '修改'}}</button>
					<button class="layui-btn layui-btn-primary" @click="kit.goBack('index')">取消</button>
				</div>
			</div>
		</form>

	</layout>
</template>

<script>
	export default {
		data() {
			return {
				loading: true ,
				data : {
					id : '',
					address:"",
					latitude : "" ,
					longitude : ''
				}
			}
		},
		onLoad(params) {
			this.data.id = params.id || "" ;
			this.loadData();
		},
		onShow() {
			
		},
		methods: {
			
			chooseLocation:function(e){
				uni.chooseLocation({
					latitude: this.data.latitude ,
					longitude : this.data.longitude ,
					type : "gcj02",
					success: (res) => {
						this.data.latitude = res.latitude ;
						this.data.longitude = res.longitude ;
						this.data.address = res.address + res.name ;
					}
				})
			},
			
			submit:function(e){
				this.form.submit(e);
			},
			
			loadData : function(e){
				var that = this ;
				var data = {
					id : this.data.id
				} ;
				this.kit.get("/admin/company/info",data,function(res){
					that.data = res.data || that.data ;	
					that.loading  = false ;
				});
			}
		}
	}
</script>